home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / perl / perlvisi.1 / perlvisi / perlvision / rap < prev    next >
Encoding:
Text File  |  1995-03-22  |  18.4 KB  |  716 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # PerlVision - A class library to do ANSI graphics and textmode GUI
  4. # By Ashish Gulhati (hash@well.sf.ca.us)
  5. # V.0.1.0
  6. #
  7. # (C) Ashish Gulhati, 1995. All Rights Reserved.
  8. #
  9. # Free electronic distribution permitted. You are free to use
  10. # PerlVision in your own code so long as this copyright message stays
  11. # intact. PerlVision or derived code may not be used in any commercial
  12. # product without my prior written or PGP-signed consent. Please e-mail 
  13. # me if you make significant changes, or just want to let me know what 
  14. # you're using PerlVision for.
  15.  
  16. # RAP (Rap Ain't Pico) is a small text editor provided as an example
  17. # of how to code using PerlVision and what PerlVision programs look
  18. # like. If you'd like to provide rap as an editor on your system for
  19. # inexperienced users, just great! They'll get used to emacs keybindings
  20. # for basic stuff and won't find it intimidating to move to the mother
  21. # of all editors later. ;-) I use rap as a pico replacement on my
  22. # system. RAP (but not the rest of PerlVision) is distributed under
  23. # the terms of the Gnu General Public License, see file COPYING.
  24.  
  25. require 5.000;
  26. require ("perlvision.pl");
  27.  
  28. package MY_Editor;
  29.  
  30. @ISA = (PV_Editbox);
  31.  
  32. sub new {            # A better mousetrap
  33.     my $type=shift;        # MY_Editor (margin,text,index,filename);
  34.     my @params=(@_);
  35.     my $self=new PV_Editbox (2,4,79,23,@params[0..2],0);
  36.     &pv::set_cur_pos(1,24);
  37.     &pv::fgcolor(4);
  38.     &pv::pvprint("  <Esc>-H for Help             <Esc>-X for Menu");
  39.     $$self[11]=0;        # Mark position
  40.     $$self[12]="INS  TOP";    # status
  41.     $$self[13]="";        # status shown
  42.     $$self[14]=$params[3];    # filename
  43.     $$self[15]="";        # Kill buffer
  44.     $$self[16]=0;        # Kill buffer clear toggle
  45.     ($$self[14] =~/^~/) && (substr ($$self[14],0,1)=(getpwuid ($<))[7]);
  46.     bless $self;
  47. }
  48.  
  49. sub statusbar {
  50.     my $self=shift;
  51.     substr ($$self[12],0,3) = ($$self[10] ? "OVT" : "INS");
  52.     if ($$self[12] ne $$self[13]) {
  53.     &pv::set_cur_pos(71,24);
  54.     &pv::pvprint($$self[12]);
  55.     &pv::refresh();
  56.     $$self[13]=$$self[12];
  57.     }
  58. }
  59.  
  60. sub cursor {
  61.     my $self=shift;
  62.     my $total = $#{$$self[8]};
  63.     my @ret=$self->PV_Editbox::cursor();
  64.     if ($$self[7]==0) {
  65.     if ($total < 18) {
  66.         substr ($$self[12],5) = "ALL";
  67.     }
  68.     else {
  69.         substr ($$self[12],5) = "TOP";
  70.     }
  71.     }
  72.     elsif (($$self[7]+18) > $total) {
  73.     substr ($$self[12],5) = "BOT";
  74.     }
  75.     else {
  76.     my $percent = $ret[1]/$total*100;
  77.     substr ($$self[12],5)=sprintf("%2d%",$percent);
  78.     }
  79.     return @ret;
  80. }
  81.  
  82. sub help {
  83.     my $helptext="Help for RAP? You want help for RAP???
  84.  
  85. Just kidding. RAP is a very basic editor that uses
  86. emacs-like keystrokes for most things. Here's a
  87. summary:
  88.  
  89. Keystroke sequences are presented in the Emacs format: 
  90. C-<key> means hold down 'CONTROL' and type <key>. 
  91. M-<key> means hold down 'ALT' and type <key>, or 
  92. alternately, press 'ESCAPE' and then press <key>.
  93.  
  94. Movement Commands:
  95.  
  96. Arrow keys, Page Up, Page Down should work. If not, 
  97. there are alternates:
  98.  
  99. C-f         Move forward one character
  100. C-b         Move back one character
  101. C-n         Move down one line
  102. C-p         Move up one line
  103.  
  104. C-v         Move down a page
  105. M-v         Move up a page
  106.  
  107. C-a         Move to beginning of line
  108. C-e         Move to end of line
  109.  
  110. M-<         Move to beginning of text
  111. M->         Move to end of text
  112.  
  113.  
  114. Editing Commands:
  115.  
  116. Typing any printable character inserts it into your 
  117. text. Del, backspace, and insert should work. If not,
  118. there are alternates:
  119.  
  120. M-i         Toggles insert/overwrite mode
  121. C-h         Backspace
  122. C-d         Delete
  123.  
  124. M-d         Delete word forward
  125. C-k         Delete to end of line
  126.  
  127. C-k behaves the way it does in Emacs. The first time 
  128. around, it kills everything on the line. The second
  129. time around, it kills the line itself.
  130.  
  131. Any text killed with C-k or M-d is inserted into the
  132. 'cut buffer', and can be pasted back into your text
  133. at the same or a different location with a C-y. See
  134. below.
  135.  
  136.  
  137. Block Commands:
  138.  
  139. Any command that kills more than one character of text
  140. adds that to the 'cut buffer'. The first time you kill
  141. multiple characters, the cut buffer is started afresh,
  142. and subsequent kills keep adding to it, until you do 
  143. something that is not a multi-character kill.
  144.  
  145. All the text in the cut buffer can be pasted back into 
  146. your text with a 
  147.  
  148. C-y         Paste cut buffer into text
  149.  
  150. This doesn't clear the cut buffer, and you can paste
  151. as many times as you like. Other commands that operate
  152. on blocks:
  153.  
  154. C-<space>   Sets 'mark' at current cursor position.
  155.  
  156. C-w         Kills all text between 'mark' and current
  157.             cursor position.
  158.  
  159. M-w         Copy all text between 'mark' and current 
  160.             cursor position to the cut buffer, but
  161.             don't kill it.
  162.  
  163. With these commands you can go to some point in your
  164. text, set 'mark', then go to some other position, and
  165. use C-w or M-w to either kill the region or copy it to
  166. the cut buffer without killing it. Now it's ready to be
  167. pasted back into your text wherever you like.
  168.  
  169. RAP doesn't, and never will, support a kill-ring like 
  170. Emacs.
  171.  
  172.  
  173. File Commands:
  174.  
  175. C-x C-f     Opens a file for editing
  176. C-x C-i     Inserts another file into your text
  177. C-x s       Saves the file you are editing
  178. C-x C-w     Write editor text out to some other file
  179. C-x k       Forget current file and clear the editor
  180. C-x C-c     Quits the editor
  181.  
  182.  
  183. Miscellaneous Commands:
  184.  
  185. M-x         Gets you to the menu
  186. M-h         Does something very dangerous. DO NOT USE!
  187.  
  188.  
  189. The menu bar:
  190.  
  191. A number of the things mentioned above can also be done
  192. from the menu bar, but that's really just there because
  193. it looks pretty. Everything can be accomplished much
  194. faster using the right keystrokes.
  195.  
  196. Two things that can be accessed only from the menu bar
  197. are the RAP 'About Box' and the Preferences dialog
  198. (which has a lot of useful options you can set to
  199. customize your RAP editing environment just like with
  200. Emacs lisp ;-)
  201.  
  202.  
  203. Shareware Terms & Emacs:
  204.  
  205. If after 10 days of using RAP you find it useful you
  206. must either switch to Emacs and delete RAP from your
  207. disk, or send me \$1,000,000 at:
  208.  
  209. 140 Sunder Nagar,
  210. New Delhi - 110003,
  211. India.
  212.  
  213. Please send only A/C payee checks made out to 'Ashish
  214. Gulhati' and write your name and email address at the
  215. back of the check.
  216.  
  217. Shareware only works if authors have the support of
  218. users like yourself. Please don't ignore these shareware
  219. terms.  Thank you!
  220.  
  221.  
  222.  
  223.                    _/_/_/      _/ _/_/_/
  224.                   _/   _/   _/_/ _/   _/ 
  225.                  _/_/_/  _/_/_/ _/_/_/  
  226.                 _/_/  _/_/_/_/ _/       
  227.                _/  _/_/_/_/_/ _/    
  228.                     _/
  229.                      _/
  230.      
  231.                      RAP Ain't Pico
  232.                 (C) 1995, Ashish Gulhati";
  233.  
  234.     my $help1 = PV_Viewbox::new ("",10,7,70,18,$helptext,0);
  235.     my $help2 = PV_Pushbutton::new (""," OK ",36,19);
  236.     my $help = PV_Dialog::new ("","",8,6,72,22,1,6,
  237.               $help1,0,0,0,0,1,1,2,0,
  238.               $help2,1,2,2,1,2,3,1,0);
  239.     $help->activate;
  240. }
  241.  
  242. sub options {
  243.     my $fun0 = PV_Static::new ("","On Startup:",22,9,40,9);
  244.     my $fun1 = PV_Checkbox::new ("","Mail president\@whitehouse.gov",22,11,0,1);
  245.     my $fun2 = PV_Checkbox::new ("","Play a Rush song:",22,12,0,1);
  246.     my $fun3 = PV_Listbox::new ("","Song",26,14,42,19,
  247.                    "Force Ten",0,
  248.                    "The Trees",0,
  249.                    "Kid Gloves",0,
  250.                    "Tom Sawyer",0,
  251.                    "Tai Shan",0,
  252.                    "2112",0,
  253.                    "Red Sector A",0,
  254.                    "Freewill",0,
  255.                    "Anthem",0);
  256.     my $fun4 = PV_Radio::new ("","Lo Volume",44,14,0,1);
  257.     my $fun5 = PV_Radio::new ("","Hi Volume",44,15,1,1);
  258.     my $fun6 = PV_RadioG::new ("",$fun4, $fun5);
  259.     my $fun7 = PV_Pushbutton::new ("","Yes",47,17);
  260.     my $options = PV_Dialog::new ("","",20,8,59,20,1,6,
  261.                  $fun1,1,2,2,1,1,1,2,0,
  262.                  $fun2,1,3,3,1,2,2,3,0,
  263.                  $fun3,0,0,4,2,3,3,4,4,
  264.                  $fun4,2,5,5,3,4,4,5,0,
  265.                  $fun5,4,6,6,3,5,5,6,0,
  266.                  $fun7,5,6,6,3,6,6,1,0,
  267.                  $fun0,0,0,0,0,0,0,0,0);
  268.     $options->activate;
  269. }
  270.  
  271. sub readfile {
  272.     my $filename=shift;
  273.     my $text="";
  274.     ($filename =~/^~/) && (substr ($filename,0,1)=(getpwuid ($<))[7]);
  275.     open (INPUT, $filename) || return (0);
  276.     foreach (<INPUT>) {
  277.     $text.=$_;
  278.     }
  279.     close INPUT;
  280.     return (1,$text);
  281. }
  282.  
  283. sub dirty {
  284.     my $self=shift;
  285.     my $dirty = ($$self[5] eq "\n") ? 0 : 1;
  286.     if ($$self[14]) {
  287.     my @origfile = readfile ($$self[14]);
  288.     if ($origfile[0]) {
  289.         $origfile[1].="\n";
  290.         ($origfile[1] eq $$self[5]) && ($dirty = 0);
  291.     }
  292.     }
  293.     return $dirty;
  294. }
  295.  
  296. sub findfile {
  297.     my $self=shift;
  298.     if ($self->dirty) {
  299.     return 0 unless (&PVD::yesno ("Sure you want to abandon this file?",40,1));
  300.     }
  301.     my $newfile = PV_Entryfield::new ("",3,24,50,0,"Find File:","");
  302.     $newfile->display; $newfile->activate;
  303.     my $filename = ($newfile->stat);
  304.     undef $newfile;
  305.     &pv::set_cur_pos(1,24);
  306.     &pv::fgcolor(4);
  307.     &pv::pvprint("  <Esc>-H for Help             <Esc>-X for Menu                  ");
  308.     &pv::refresh();
  309.     if ($filename) {
  310.     my ($ret, $initial) = readfile ($filename);
  311.     if ($ret) {
  312.         $$self[5]=$initial."\n";
  313.         $$self[6]=0;
  314.         $$self[14]=$filename;
  315.         ($$self[14] =~/^~/) && (substr ($$self[14],0,1)=(getpwuid ($<))[7]);
  316.         $self->justify(1);
  317.         $self->refresh();
  318.     }
  319.     else {
  320.         &PVD::message ("Error: Couldn't open file.",30,1);
  321.     }
  322.     }
  323.     $self->cursor;
  324.     &pv::refresh_cursor();
  325. }
  326.  
  327. sub insertfile {
  328.     my $self=shift;
  329.     my $newfile = PV_Entryfield::new ("",3,24,48,0,"Insert File:","");
  330.     $newfile->display; $newfile->activate;
  331.     my $filename = ($newfile->stat);
  332.     undef $newfile;
  333.     &pv::set_cur_pos(1,24);
  334.     &pv::fgcolor(4);
  335.     &pv::pvprint("  <Esc>-H for Help             <Esc>-X for Menu                  ");
  336.     &pv::refresh();
  337.     if ($filename) {
  338.     my ($ret, $initial) = readfile ($filename);
  339.     if ($ret) {
  340.         substr ($$self[5],$$self[6],0)=$initial;
  341.         $self->justify(1);
  342.         $self->refresh();
  343.     }
  344.     else {
  345.         &PVD::message ("Error: Couldn't open file.",30,1);
  346.     }
  347.     }
  348.     $self->cursor;
  349.     &pv::refresh_cursor();
  350. }
  351.  
  352. sub saveas {
  353.     my $self=shift;
  354.     my $savefile = PV_Entryfield::new ("",3,24,52,0,"Save As:",$$self[14]);
  355.     $savefile->display; $savefile->activate;
  356.     my $filename = ($savefile->stat);
  357.     ($filename =~/^~/) && (substr ($filename,0,1)=(getpwuid ($<))[7]);
  358.     undef $savefile;
  359.     &pv::set_cur_pos(1,24);
  360.     &pv::fgcolor(4);
  361.     &pv::pvprint("  <Esc>-H for Help             <Esc>-X for Menu                  ");
  362.     &pv::refresh();
  363.     if ($filename) {
  364.     if (-e $filename) {
  365.         return unless (&PVD::yesno ("File exists. Overwrite?",30,1));
  366.     }
  367.     $$self[14]=$filename;
  368.     $self->savefile;
  369.     }
  370.     $self->cursor;
  371.     &pv::refresh_cursor();
  372. }
  373.  
  374. sub savefile {
  375.     my $self=shift;
  376.     if ($$self[14]) {
  377.     if ($self->dirty) {
  378.         open (SAVE, ">$$self[14]") || do {
  379.         &PVD::message ("Error: Couldn't open file.",40,12);
  380.         return;
  381.         };
  382.         chop $$self[5];
  383.         print SAVE $$self[5];
  384.         close (SAVE);
  385.         $$self[5].="\n";
  386.     }
  387.     }
  388.     else {
  389.     $self->saveas();
  390.     }
  391. }
  392.  
  393. sub killfile {
  394.     my $self=shift;
  395.     if ($self->dirty) {
  396.     return 0 unless (&PVD::yesno ("Sure you want to abandon this file?",40,1));
  397.     }
  398.     $$self[5]="\n";
  399.     $$self[6]=0;
  400.     $$self[14]="";
  401.     $self->justify(1);
  402.     $self->refresh();
  403.     return 1;
  404. }
  405.  
  406. sub word {
  407.     my $self=shift;
  408.     my $dir=shift;
  409.     my $chars="";
  410.     if ($dir) {
  411.     $chars = substr ($$self[5],$$self[6]);
  412.     $chars =~ s/(\W*\w+).*/$1/s;
  413.     }
  414.     else {
  415.     $chars = substr ($$self[5],0,$$self[6]);
  416.     $chars =~ s/.*\W(\w)/$1/s;
  417.     }
  418.     return (length ($chars));
  419. }
  420.  
  421. sub wordforward {
  422.     my $self=shift;
  423.     $$self[6]+=$self->word(1);
  424.     $$self[6]==length($$self[5]) && $$self[6]--;
  425.     $self->cursor;
  426.     &pv::refresh_cursor;
  427. }
  428.  
  429. sub wordback {
  430.     my $self=shift;
  431.     $$self[6]-=$self->word(0);
  432.     $self->cursor;
  433.     &pv::refresh_cursor;
  434. }
  435.  
  436. sub wordkill {
  437.     my $self=shift;
  438.     my $chars = $self->word(1);
  439.     $$self[6]+$chars==length($$self[5]) && $chars--;
  440.     $$self[16] && ($$self[15].=substr ($$self[5],$$self[6],$chars));
  441.     $$self[16] || ($$self[15]=substr ($$self[5],$$self[6],$chars));
  442.     $$self[16] = 1;
  443.     substr ($$self[5],$$self[6],$chars) = "";
  444.     $self->justify();
  445.     $self->refresh;
  446.     $self->cursor;
  447.     &pv::refresh_cursor();
  448. }
  449.  
  450. sub linekill {
  451.     my $self=shift;
  452.     my $chars = substr ($$self[5],$$self[6]);
  453.     $chars =~ s/\n.*/\n/s;
  454.     if ($chars eq "\n") {
  455.     $chars = 1;
  456.     }
  457.     else {
  458.     $chars = length ($chars)-1;
  459.     }
  460.     $$self[6]+$chars==length($$self[5]) && $chars--;
  461.     $$self[16] && ($$self[15].=substr ($$self[5],$$self[6],$chars));
  462.     $$self[16] || ($$self[15]=substr ($$self[5],$$self[6],$chars));
  463.     $$self[16] = 1;
  464.     substr ($$self[5],$$self[6],$chars) = "";
  465.     $self->justify();
  466.     $self->refresh;
  467.     $self->cursor;
  468.     &pv::refresh_cursor();
  469. }
  470.  
  471. sub setmark {
  472.     my $self=shift;
  473.     $$self[11]=$$self[6];
  474.     &pv::set_cur_pos(1,24);
  475.     &pv::fgcolor(0); &pv::bgcolor(6);
  476.     &pv::pvprint("  Mark Set                                     ");
  477.     &pv::refresh;
  478.     sleep (1);
  479.     &pv::set_cur_pos(1,24);
  480.     &pv::fgcolor(4);
  481.     &pv::pvprint("  <Esc>-H for Help             <Esc>-X for Menu");
  482.     &pv::refresh;
  483.     $self->cursor;
  484.     &pv::refresh_cursor();
  485. }
  486.  
  487. sub regionkill {
  488.     my $self=shift;
  489.     my $reallykill=shift;
  490.     my $start = (($$self[11] > $$self[6]) ? $$self[6] : $$self[11]);
  491.     my $chars = (($$self[11] > $$self[6]) ? $$self[11] : $$self[6]) - $start;
  492.     $$self[16] && ($$self[15].=substr ($$self[5],$start,$chars));
  493.     $$self[16] || ($$self[15]=substr ($$self[5],$start,$chars));
  494.     $$self[16] = 1;
  495.     if ($reallykill) {
  496.     $$self[6]=$start;
  497.     substr ($$self[5],$start,$chars) = "";
  498.     $self->justify();
  499.     $self->refresh;
  500.     $self->cursor;
  501.     &pv::refresh_cursor();
  502.     }
  503. }
  504.  
  505. sub yank {
  506.     my $self=shift;
  507.     substr ($$self[5],$$self[6],0)=$$self[15];
  508.     $$self[6]+=length($$self[15]);
  509.     $self->justify(1);
  510.     $self->refresh();
  511.     $self->cursor;
  512.     &pv::refresh_cursor();
  513. }
  514.  
  515. sub beginning {
  516.     my $self=shift;
  517.     $$self[6]=0;
  518.     $self->cursor;
  519.     &pv::refresh_cursor;
  520. }
  521.  
  522. sub end {
  523.     my $self=shift;
  524.     $$self[6]=length($$self[5])-1;
  525.     $self->cursor;
  526.     &pv::refresh_cursor;
  527. }
  528.  
  529. sub process_key {
  530.     my $self=shift;
  531.     my @key=(@_);
  532.     if ($key[1]==14) {
  533.     $self->wordkill;
  534.     return (2);
  535.     }
  536.     elsif ((!$key[1]) && ($key[0] eq " ")) {
  537.     $self->linekill;
  538.     return (2);
  539.     }
  540.     elsif ((!$key[1]) && ($key[0] eq "")) {
  541.     $self->regionkill(1);
  542.     return(2);
  543.     }
  544.     elsif ($key[1]==22) {
  545.     $self->regionkill(0);
  546.     return(2);
  547.     }
  548.     $$self[16]=0;
  549.     (($key[1]==200) && ($key[0] eq "\t")) && (return (2)); # Override TAB
  550.     if ((!$key[1]) && ($key[0] eq "")) {
  551.     $self->setmark;
  552.     return(2);
  553.     }
  554.     if ((!$key[1]) && ($key[0] eq "")) { # ^X begins most commands
  555.     @key=&pv::getkey();
  556.     ((!$key[1]) && ($key[0] eq "")) && (return (1)); # Quit
  557.     ((!$key[1]) && ($key[0] eq "")) && do {          # Find file
  558.         $self->findfile();
  559.         return (2);
  560.     };
  561.     (($key[1]==200) && ($key[0] =~ /[iI]/)) && do {    # Insert file
  562.         $self->insertfile();
  563.         return (2);
  564.     };
  565.     ((!$key[1]) && ($key[0] eq "")) && do {          # Save file
  566.         $self->savefile;
  567.         return (2);
  568.     };
  569.     (($key[1]==200) && ($key[0] =~ /[sS]/)) && do {    # Save file
  570.         $self->savefile;
  571.         return (2);
  572.     };
  573.     ((!$key[1]) && ($key[0] eq "")) && do {          # Write file
  574.         $self->saveas;
  575.         return (2);
  576.     };
  577.     (($key[1]==200) && ($key[0]=~/[Kk]/)) && do {      # Abandon file
  578.         $self->killfile;
  579.         return (2);
  580.     };
  581.     return (3,@key);
  582.     }
  583.     elsif ($key[1]==20) {
  584.     $self->wordforward;
  585.     return (2);
  586.     }
  587.     elsif ($key[1]==13) {
  588.     $self->wordback;
  589.     return (2);
  590.     }
  591.     elsif ($key[1]==16) {
  592.     $self->beginning;
  593.     return (2);
  594.     }
  595.     elsif ($key[1]==17) {
  596.     $self->end;
  597.     return (2);
  598.     }
  599.     elsif ((!$key[1]) && ($key[0] eq "")) {
  600.     $self->yank;
  601.     return (2);
  602.     }
  603.     else {
  604.     return 0;
  605.     }
  606. }
  607.  
  608. package main;
  609.  
  610. sub readfile {
  611.     my $filename=shift;
  612.     my $text="";
  613.     ($filename =~/^~/) && (substr ($filename,0,1)=(getpwuid ($<))[7]);
  614.     open (INPUT, $filename) || return (0);
  615.     foreach (<INPUT>) {
  616.     $text.=$_;
  617.     }
  618.     close INPUT;
  619.     return (1,$text);
  620. }
  621.  
  622. $initial="";
  623.  
  624. $COPYRIGHT = "
  625. RAP (RAP ain't Pico) Copyright (C) 1995, Ashish Gulhati.
  626. A simple text editor for newcomers to Unix, with Emacs-like
  627. keybindings to ease the upgrade path ;-)
  628.  
  629. ";
  630.  
  631. $ABOUT="
  632.            _/_/_/      _/ _/_/_/
  633.           _/   _/   _/_/ _/   _/ 
  634.          _/_/_/  _/_/_/ _/_/_/  
  635.         _/_/  _/_/_/_/ _/       
  636.        _/  _/_/_/_/_/ _/    
  637.             _/
  638.              _/
  639.      
  640.              RAP Ain't Pico
  641.         (C) 1995, Ashish Gulhati
  642. ";
  643.  
  644. (($#ARGV >0) || ($ARGV[0] =~/^-/)) && die ($COPYRIGHT."Usage:\nrap [filename]\n\n");
  645. if ($#ARGV == 0) {
  646.     ($ret, $initial) = readfile ($ARGV[0]);
  647.     $ret || die ($COPYRIGHT."Couldn't open $ARGV[0]\n\n");
  648.     undef $ret;
  649. }    
  650.  
  651. pv::initvision(1);
  652. pv::standard();
  653. pv::set_cur_pos(1,24);
  654. pv::bgcolor(6);
  655. pv::cleol();
  656.  
  657. $menu = new PV_Menubar("File",18,9,
  658.                "Open    C-x C-f",0,
  659.                "Insert    C-x i",0,
  660.                "Save      C-x s",0,
  661.                "Save As C-x C-w",0,
  662.                "Abandon   C-x k",0,
  663.                "Quit    C-x C-c",0,
  664.                "Help        M-h",0,
  665.                "About          ",0);
  666. $menu->add("Edit",20,8,
  667.        "Set Mark  C-<Spc>",0,
  668.        "Cut Region    C-w",0,
  669.        "Copy Region   M-w",0,
  670.        "Paste         C-y",0,
  671.        "Del Word      M-d",0,
  672.        "Del Line      C-k",0,
  673.        "Preferences      ",0);
  674.  
  675. $editor = new MY_Editor(60,$initial,0,$ARGV[0]);
  676. $editor->display;
  677. $menu->display;
  678.  
  679. while (true) {
  680.     $ret=$editor->activate();
  681.     if ($ret == 8) {
  682.     @menuselect = (8, "File:Quit    C-x C-c");
  683.     }
  684.     elsif ($ret == 5) {
  685.     @menuselect = (8, "File:Help        M-h");
  686.     }
  687.     else {
  688.     @menuselect=($menu->activate);
  689.     }
  690.     if ($menuselect[0] == 5) {
  691.     @menuselect = (8, "File:Help        M-h");
  692.     }
  693.     if ($menuselect[0] == 8) {
  694.     ($menuselect[1] eq "Edit:Cut Region    C-w") && ($editor->regionkill(1));
  695.     ($menuselect[1] eq "Edit:Copy Region   M-w") && ($editor->regionkill(0));
  696.     ($menuselect[1] eq "Edit:Del Word      M-d") && ($editor->wordkill);
  697.     ($menuselect[1] eq "Edit:Del Line      C-k") && ($editor->linekill);
  698.     $$editor[16]=0;
  699.  
  700.     ($menuselect[1] eq "File:Open    C-x C-f") && ($editor->findfile);
  701.     ($menuselect[1] eq "File:Insert    C-x i") && ($editor->insertfile);
  702.     ($menuselect[1] eq "File:Save      C-x s") && ($editor->savefile);
  703.     ($menuselect[1] eq "File:Save As C-x C-w") && ($editor->saveas);
  704.     ($menuselect[1] eq "File:Abandon   C-x k") && ($editor->killfile);
  705.     ($menuselect[1] eq "File:Quit    C-x C-c") && ($editor->killfile && last);
  706.     ($menuselect[1] eq "File:Help        M-h") && ($editor->help);
  707.     ($menuselect[1] eq "File:About          ") && (PVD::message ($ABOUT,40,11));
  708.  
  709.     ($menuselect[1] eq "Edit:Set Mark  C-<Spc>") && ($editor->setmark);
  710.     ($menuselect[1] eq "Edit:Preferences      ") && ($editor->options);
  711.     ($menuselect[1] eq "Edit:Paste         C-y") && ($editor->yank);
  712.     }
  713. }
  714.  
  715. pv::exitvision();
  716.